#!/bin/bash

macToolConfigBlockSym="# ===== MacTool Config ====="
configFileName="self_config_profile.sh"
downloadPath=$(pwd)
MacToolPath="$downloadPath/MacEffectiveTool"
profilePaths=("$HOME/.bash_profile" "$HOME/.zshrc")
accountName="zxinsunshine"
gitsourceUrl="https://${accountName}@gitee.com/zxinsunshine/MacEffectiveTool.git"

# 下载工具资源
git -C $downloadPath clone $gitsourceUrl

# 植入关联
configLine=("")
configLine+="\n"
configLine+=$macToolConfigBlockSym
configLine+="\n"
configLine+="# Attention ! This Block can't be modified! "
configLine+="\n"
configLine+="export MacToolPath='$MacToolPath'"
configLine+="\n"
configLine+="export MacToolCmd='python'"
configLine+="\n"
configLine+="export MacToolAccount='$accountName'"
configLine+="\n"
configLine+="source $MacToolPath/$configFileName"
configLine+="\n"
configLine+=$macToolConfigBlockSym
configLine+="\n"
configLine+=""

for p in ${profilePaths[@]}
do
echo -e "$configLine" >> $p
done

source $MacToolPath/$configFileName

# 删除密码钥匙串
echo "security delete-internet-password -a $accountName"
security delete-internet-password -a $accountName

echo "finished"
